package com.dreamtour.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamtour.entity.Posts;
import com.dreamtour.entity.Services;
import com.dreamtour.mapper.PostsMapper;
import com.dreamtour.mapper.ServicesMapper;
import com.dreamtour.service.IPostsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xls
 * @since 2024-12-24
 */
@Service
public class PostsServiceImpl extends ServiceImpl<PostsMapper, Posts> implements IPostsService {
    @Autowired
    private PostsMapper postsMapper;

    @Override
    public List<Map<String, Object>> countPostsByMonth() {
        QueryWrapper<Posts> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("count(*) as count, DATE_FORMAT(postTime, '%m') as month");
        queryWrapper.groupBy("month");
        queryWrapper.orderByDesc("month");
        return postsMapper.selectMaps(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> getDailyPosts(){
        return postsMapper.getDailyPosts();
    }

    @Override
    public Posts findById(Integer postId) {
        return postsMapper.selectById(postId);
    }
}
